package nodetest;
public class LinkedStack {
    // this should hold a LinkedStack of nodes...
    private Node top; //# reference to the top node
    private int size; //# number of elements in the LinkedStack
    
    
    public LinkedStack() {      //# Initialize the LinkedStack
        top = null;
        size = 0;
    }
    public int size() { //# Returns the current stack size
        return size;
    }
    public boolean isEmpty() { //# Returns true if the stack is empty
        if (top == null) {
            return true;
        }
        return false;
    }
    public Object top() throws StackException { // Return the top stack // element
        if (isEmpty()) {
            throw new StackException("Stack is empty.");
        }
        return top.getElement();
    }
    public void push(Object obj) { // Push a new object on the stack

        Node n = new Node();

        n.setElement(obj);

        n.setNext(top);

        top = n;

        size++;

    }
    public Object pop() throws StackException { // Pop off the top stack element
        Object temp;
        if (isEmpty()) {
            throw new StackException("Stack is empty.");
        }
        temp = top.getElement();
        top = top.getNext(); // link-out the top node
        size--;
        return temp;
    }



}
